import requests

# 定义deepseek函数，输入是question(要问的问题)，输出是answer(大模型回答)
def deepseek(question):
    url = "https://api.siliconflow.cn/v1/chat/completions"

    payload = {
        "model": "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B",
        "stream": False,
        "max_tokens": 1024,
        "temperature": 0.7,
        "top_p": 0.7,
        "top_k": 50,
        "frequency_penalty": 0.5,
        "n": 1,
        "stop": [],
        "messages": [
            {
                "role": "user",
                "content": question
            }
        ]
    }
    headers = {
        "Authorization": "Bearer sk-ztjdijjdzgjnmilnsbwtogdvadchciehkjgfuspwhirvvvdw",
        "Content-Type": "application/json"
    }

    response = requests.request("POST", url, json=payload, headers=headers)

    # print(response.text)
    # 可以使用JSON提取回答信息
    return response.json().get("choices")[0].get("message").get("content")
    # TODO 优化返回值


# 调用deepseek函数，问：给我讲个冷笑话
print(deepseek("给我讲一个冷笑话"))